package org.example.service.impl;

import cn.hutool.crypto.digest.BCrypt;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.mapper.UserMapper;
import org.example.domain.po.User;
import org.example.service.IUserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService{

    @Override
    public Boolean queryUser(User user) {
        String pwd=lambdaQuery()
                .eq(User::getAccount,user.getAccount())
                .one()
                .getPassword();
        return BCrypt.checkpw(user.getPassword(),pwd);
    }

    @Override
    public void forgotPwd(User user) {
        lambdaUpdate()
                .eq(User::getAccount,user.getAccount())
                .set(User::getPassword,BCrypt.hashpw(user.getPassword(),BCrypt.gensalt()))
                .update();
    }

    @Override
    public User getOne(String account) {
        return lambdaQuery()
                .eq(User::getAccount,account)
                .one();
    }
}
